package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.ActivityOrderListBean;
import com.example.administrator.yuejian_2.viewholder.ActivityOrderListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/10.
 */

public class ActivityOrderListAdapter extends RecyclerView.Adapter {
    private List<ActivityOrderListBean> activityorder = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public ActivityOrderListAdapter(Context context, List<ActivityOrderListBean> activityorder){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.activityorder.addAll(activityorder);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_activityorder,parent,false);
        ActivityOrderListViewHolder holder = new ActivityOrderListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActivityOrderListViewHolder activityorderholder = (ActivityOrderListViewHolder) holder;
        ActivityOrderListBean activityorderlist = activityorder.get(position);
        activityorderholder.number.setText(activityorderlist.getOnumber());

        int price = activityorderlist.getA_money();
        int i = activityorderlist.getAmount();
        int sums = i * price;
        String s = Integer.toString(sums);
        activityorderholder.sum.setText("总价 :"+ s +"元");
        activityorderholder.activity_name.setText("活动名称 :" + activityorderlist.getA_name());
        activityorderholder.time.setText("下单时间 :" + activityorderlist.getTime());
        String activity_picture = activityorderlist.getA_pic();
        if (!activity_picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+activity_picture)
                    .into(activityorderholder.activity_pic);

        final int aid = activityorderlist.getAid();
//        activityorderholder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(context, AcDetailActivity.class);
//                intent.putExtra("aid",aid);
//                context.startActivity(intent);
//
//            }
//        });


    }

    @Override
    public int getItemCount() {
        return activityorder.size();
    }
}

